package com.misboot.document.controller;


import cn.ewsd.common.annotation.ControllerLog;
import cn.ewsd.common.bean.LoginInfo;
import cn.ewsd.common.utils.StringUtils;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import com.misboot.document.constants.MacroDefinitionData;
import com.misboot.document.constants.RequestLogType;
import com.misboot.document.client.FormClient;
import com.misboot.document.filter.loginInfo.LoginInfoVo;
import com.misboot.document.model.DfsFile;
import com.misboot.document.model.OfDocument;
import com.misboot.document.model.OfDocumentVersioning;
import com.misboot.document.service.DfsFileService;
import com.misboot.document.service.OfDocumentService;
import com.misboot.document.service.OfDocumentVersioningService;
import com.misboot.document.utils.BaseUtils;
import com.misboot.document.utils.DateUtils;
import com.misboot.document.utils.PageUtil.PageParam;
import com.misboot.document.utils.PageUtil.PageSet;
import com.misboot.document.utils.RegexUtil;
import com.misboot.document.utils.Result;
import com.misboot.document.utils.file.FileUtils;
import com.misboot.document.utils.minio.MinioUtil;
import com.misboot.document.vo.MinioVo;
import io.minio.*;
import io.minio.errors.*;
import io.minio.http.Method;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import tk.mybatis.mapper.entity.Example;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.List;
import java.util.concurrent.TimeUnit;


/**
 * minio文件管理
 *
 * @Author 湖南佐佑时代科技有限公司
 * @Version 5.4.21
 * @Email service@zuoyo.com
 * @Date 2022-06-13 09:39:40
 */
@Api(tags = {"minio文件管理"})
@Controller
@RequestMapping("/minio")
public class MinioController extends DocumentBaseController {

    static Logger logger = LoggerFactory.getLogger(MinioController.class);


    @Autowired
    MinioUtil minioUtil;

    /**
     * 地址
     */
    @Value("${minio.urlW}")
    private String minioUrl;

    @Autowired
    private MinioClient minioClient;

    @Autowired
    private DfsFileService dfsFileService;

    @Autowired
    private FormClient formClient;


    @ResponseBody
    @RequestMapping(value = "/getPageSet", method = RequestMethod.POST)
    @ControllerLog(description = "获得DfsFile分页集数据")
    @ApiOperation(value = "获得分布式文件分页集数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", required = true, dataType = "Int"),
            @ApiImplicitParam(name = "rows", value = "一页显示多少条记录", defaultValue = "20", required = true, dataType = "Int"),
            @ApiImplicitParam(name = "sort", value = "排序", defaultValue = "createTime", required = true, dataType = "String"),
            @ApiImplicitParam(name = "order", value = "排序规则", defaultValue = "desc", required = true, dataType = "String")
    })
    public Object getPageSet(PageParam pageParam, String fileName, String puuid) {
        String filterSort = "";
        filterSort = BaseUtils.filterSort(request, filterSort);
        PageSet<DfsFile> pageSet = dfsFileService.getPageSet(pageParam, filterSort, fileName, puuid);
        return pageSet;
    }

    /**
     * 上传文件
     *
     * @param bucket     存储桶名称  misboot-cloud-vue
     * @param objectName 保存在存储桶的文件 images/
     * @param puuid      业务UUID
     * @return Object
     */
    @ApiOperation("上传文件")
    @RequestMapping(value = "/uploadfile", method = RequestMethod.POST)
    @ResponseBody
    public Object fileupload(@RequestParam String bucket,
                             @RequestParam(required = false) String objectName,
                             @RequestParam(required = false) String puuid, HttpServletRequest request
    ) throws Exception {
        //获取传过来的文件
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
        if (CollUtil.isEmpty(files)) {
            return failure("上传文件不能为空！！！");
        }
        //查询敏感字判断
        String sensitives = MacroDefinitionData.SENSITIVE;
        List<String> sensitiveList = Arrays.asList(sensitives.split(","));
//        for (String sensitive: sensitiveList){
//            if(objectName.contains(sensitive)){
//                throw new Exception("上传文件失败，文件名称包含有敏感词！");
//            }
//        }
        for (int i = 0; i < files.size(); i++) {
            if (ObjectUtil.isEmpty(files.get(i)) || files.get(i).getSize() <= 0) {
                return failure("上传文件不能为空！！！");
            }
            String fileName = files.get(i).getOriginalFilename();
            for (String sensitive : sensitiveList) {
                if (fileName.contains(sensitive)) {
                    throw new Exception("上传文件失败，上传文件包含有敏感词！");
                }
            }
        }
        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        String createTime = "";
        for (int i = 0; i < files.size(); i++) {
            //上传文件同名，文件名特殊处理
            String originalFilename = files.get(i).getOriginalFilename();//原始文件名
            String fileName = originalFilename;

            //特殊处理-解决使用URL获取minio文件报错的问题
            fileName = fileName.replaceAll("\\(","").replaceAll("\\)","");
            fileName = fileName.replaceAll("\\（","").replaceAll("\\）","");
            fileName = fileName.replaceAll(" ","");

            List<DfsFile> list = dfsFileService.getMaxVersionByFileName(files.get(i).getOriginalFilename());
            if (CollUtil.isNotEmpty(list)) {
                fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + fileName;
                originalFilename = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + files.get(i).getOriginalFilename();
            }
            if (StringUtils.isNullOrEmpty(objectName)) {
                objectNames = fileName;
            } else {
                objectNames = objectName + "/" + fileName;
            }
            ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(files.get(i).getInputStream(), bucket, objectNames);
            DfsFile dfsFile = new DfsFile();
            dfsFile.setRemark(files.get(i).getOriginalFilename());
            dfsFile.setFileName(originalFilename);
            dfsFile.setRemark(files.get(i).getOriginalFilename());
            dfsFile.setCreatorId(getCurrentUserNameId());
            dfsFile.setCreator(getCurrentUserName());
            dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
            dfsFile.setPuuid(puuid);
            dfsFile.setFileSize(FileUtils.getSize(files.get(i).getSize()));
            dfsFile.setTenantUuid(LoginInfoVo.getTenantUuid());
            dfsFileService.insertSelective(getSaveData(dfsFile));
            dfsFileUuid = dfsFile.getUuid();
            createTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, dfsFile.getCreateTime());
            url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
            object.add(objectWriteResponse.object());
            objectNames = null;
        }
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
        var3.put("creator", getCurrentUserName());
        var3.put("createTime", createTime);
        var3.put("docSize", FileUtils.getSize(files.get(0).getSize()));
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
//            var3.put("object", files.get(0).getOriginalFilename());
            var3.put("url", url.get(0));
        } else {
//            var3.put("object", files.get(0).getOriginalFilename());
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }


    @ApiOperation("起草正文时上传文件")
    @RequestMapping(value = "/oaUploadfile", method = RequestMethod.POST)
    @ResponseBody
    public Object oaUploadfile(@RequestParam String bucket,
                               @RequestParam(required = false) String objectName,
                               @RequestParam(required = false) String puuid, HttpServletRequest request, String beforeTemplateUuid, String nowTemplateUuid, String status
    ) throws Exception {
        //获取传过来的文件
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
        if (CollUtil.isEmpty(files)) {
            return failure("上传文件不能为空！！！");
        }
        for (int i = 0; i < files.size(); i++) {
            if (ObjectUtil.isEmpty(files.get(i)) || files.get(i).getSize() <= 0) {
                return failure("上传文件不能为空！！！");
            }
        }
        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        for (int i = 0; i < files.size(); i++) {
            String fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + files.get(i).getOriginalFilename();
            if (StringUtils.isNullOrEmpty(objectName)) {
                objectNames = fileName;
            } else {
                objectNames = objectName + "/" + fileName;
            }
            ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(files.get(i).getInputStream(), bucket, objectNames);
            url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
            object.add(objectWriteResponse.object());

            formClient.saveOfDocumentFowForm(url.get(0), puuid, beforeTemplateUuid, nowTemplateUuid, status);
            objectNames = null;
        }
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", nowTemplateUuid);
        var3.put("docSize", FileUtils.getSize(files.get(0).getSize()));
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
            var3.put("url", url.get(0));
        } else {
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }


    /**
     * 上传文件
     *
     * @param bucket     存储桶名称  misboot-cloud-vue
     * @param objectName 保存在存储桶的文件 images/
     * @param puuid      业务UUID
     * @return Object
     */
    @ApiOperation("上传文件")
    @RequestMapping(value = "/uploadMultipartFile", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadMultipartFile(@RequestPart("file") MultipartFile file,
                                      String objectName,
                                      String puuid
    ) throws Exception {
        //获取传过来的文件
        if (null == file || file.isEmpty()) {
            return failure("上传文件不能为空！！！");
        }
        //查询敏感字判断
        String sensitives = MacroDefinitionData.SENSITIVE;
        List<String> sensitiveList = Arrays.asList(sensitives.split(","));
//        for (String sensitive: sensitiveList){
//            if(objectName.contains(sensitive)){
//                throw new Exception("上传文件失败，文件名称包含有敏感词！");
//            }
//        }

        String bucket = "wps";
        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        //上传文件同名，文件名特殊处理
        String fileName = file.getOriginalFilename();
        for (String sensitive : sensitiveList) {
            if (fileName.contains(sensitive)) {
                throw new Exception("上传文件失败，上传文件包含有敏感词！");
            }
        }
        List<DfsFile> list = dfsFileService.getMaxVersionByFileName(file.getOriginalFilename());
        if (CollUtil.isNotEmpty(list)) {
            fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + file.getOriginalFilename();
        }
        if (StringUtils.isNullOrEmpty(objectName)) {
            objectNames = fileName;
        } else {
            objectNames = objectName + "/" + fileName;
        }
        ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(file.getInputStream(), bucket, objectNames);
        DfsFile dfsFile = new DfsFile();
        dfsFile.setFileName(fileName);
        dfsFile.setCreatorId(getCurrentUserNameId());
        dfsFile.setCreator(getCurrentUserName());
        dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
        dfsFile.setPuuid(puuid);
        dfsFile.setFileSize(FileUtils.getSize(file.getSize()));
//        dfsFile.setTenantUuid(LoginInfoVo.getTenantUuid());
        dfsFileService.insertSelective(getSaveData(dfsFile));
        dfsFileUuid = dfsFile.getUuid();
        url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
        object.add(objectWriteResponse.object());
        objectNames = null;
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
            var3.put("url", url.get(0));
        } else {
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }

    @ApiOperation("上传文件wps")
    @RequestMapping(value = "/uploadMultipartFileWps", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadMultipartFileWps(@RequestPart("file") MultipartFile file,
                                         String objectName,
                                         Map<String, Object> params
    ) throws Exception {
        //获取传过来的文件
        if (null == file || file.isEmpty()) {
            return failure("上传文件不能为空！！！");
        }

        //查询敏感字判断
        String sensitives = MacroDefinitionData.SENSITIVE;
        List<String> sensitiveList = Arrays.asList(sensitives.split(","));
//        for (String sensitive: sensitiveList){
//            if(objectName.contains(sensitive)){
//                throw new Exception("上传文件失败，文件名称包含有敏感词！");
//            }
//        }

        String bucket = Convert.toStr(params.get("_w_bucket"));
        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        //上传文件同名，文件名特殊处理
        String fileName = file.getOriginalFilename();
        for (String sensitive : sensitiveList) {
            if (fileName.contains(sensitive)) {
                throw new Exception("上传文件失败，文件名称包含有敏感词！");
            }
        }
        List<DfsFile> list = dfsFileService.getMaxVersionByFileName(file.getOriginalFilename());
        if (CollUtil.isNotEmpty(list)) {
            fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + file.getOriginalFilename();
        }
//        if (StringUtils.isNullOrEmpty(objectName)) {
        objectNames = fileName;
//        } else {
//            objectNames = objectName + "/" + fileName;
//        }
        ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(file.getInputStream(), bucket, objectNames);
        DfsFile dfsFile = new DfsFile();
        dfsFile.setFileName(fileName);
        dfsFile.setCreatorId(params.get("_w_createNameId").toString());
        dfsFile.setCreator(params.get("_w_createName").toString());
        dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
        dfsFile.setPuuid(params.get("_w_puuid").toString());
        dfsFile.setFileSize(FileUtils.getSize(file.getSize()));
//        dfsFile.setTenantUuid(LoginInfoVo.getTenantUuid());
        String uuid = cn.ewsd.common.utils.BaseUtils.UUIDGenerator();
        dfsFile.setUuid(uuid);
        dfsFileService.insertSelective(dfsFile);
        dfsFileUuid = dfsFile.getUuid();
        url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
        object.add(objectWriteResponse.object());
        objectNames = null;
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("bucket", bucket);
        var3.put("dfsFile", dfsFile);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
            var3.put("url", url.get(0));
        } else {
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }

    @Autowired
    private OfDocumentService ofDocumentService;

    @Autowired
    private OfDocumentVersioningService ofDocumentVersioningService;

    /**
     * 上传文件   文档管理上传附件  存在of_document数据表里面  （电子文档上传）
     *
     * @param bucket     存储桶名称  misboot-cloud-vue
     * @param objectName 保存在存储桶的文件 images/
     * @param puuid      业务UUID（父级uuid）
     * @param pid        父级id
     * @return Object
     */
    @ApiOperation("上传文件(电子文档上传)")
    @RequestMapping(value = "/uploadOfFile", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadOfFile(@RequestParam String bucket,
                               @RequestParam(required = false) String objectName, @RequestParam(required = false) String puuid,
                               @RequestParam(required = false) Integer pid, @RequestParam(required = false) String periodValidity,
                               HttpServletRequest request
    ) throws Exception {
        //这里puuid值实际传的pid的值  （由于前端主键问原因 pid值是通过puuid来带值的）
        if (StrUtil.hasBlank(Convert.toStr(puuid))) {
            throw new Exception("puuid字段不能为空");
        }

        //查询敏感字判断
        String sensitives = MacroDefinitionData.SENSITIVE;
        List<String> sensitiveList = Arrays.asList(sensitives.split(","));
//        for (String sensitive: sensitiveList){
//            if(objectName.contains(sensitive)){
//                throw new Exception("上传文件失败，文件名称包含有敏感词！");
//            }
//        }

        //判断是否审核
        //先获取父级文件夹信息
        OfDocument pOfDocument = ofDocumentService.getDataById(Integer.valueOf(puuid));
        if (!"0".equals(pOfDocument.getWhetherFolder())) {
            return failure("保存失败！新建文件必须放在文件夹下面");
        }

        //获取传过来的文件
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
        if (CollUtil.isEmpty(files)) {
            return failure("上传文件不能为空！！！");
        }
        for (int i = 0; i < files.size(); i++) {
            if (ObjectUtil.isEmpty(files.get(i)) || files.get(i).getSize() <= 0) {
                return failure("上传文件不能为空！！！");
            }
            String fileName = files.get(i).getOriginalFilename();
            for (String sensitive : sensitiveList) {
                if (fileName.contains(sensitive)) {
                    throw new Exception("上传文件失败，上传文件包含有敏感词！");
                }
            }
        }
        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        Example example1 = new Example(OfDocument.class);
        example1.orderBy("id").desc();
        List<OfDocument> ofDocumentMax = ofDocumentService.selectByExample(example1);
        for (int i = 0; i < files.size(); i++) {
            //上传文件同名，文件名特殊处理
            String fileName = files.get(i).getOriginalFilename();
            String titleName1 = fileName;
            String titleName2 = fileName;
            int lastIndex = fileName.lastIndexOf(".");
            if (lastIndex != -1) {
                titleName1 = fileName.substring(0, lastIndex);
            }

            List<DfsFile> list = dfsFileService.getMaxVersionByFileName(files.get(i).getOriginalFilename());
            if (CollUtil.isNotEmpty(list)) {
                fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + files.get(i).getOriginalFilename();
            }
            if (StringUtils.isNullOrEmpty(objectName)) {
                objectNames = fileName;
            } else {
                objectNames = objectName + "/" + fileName;
            }
            ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(files.get(i).getInputStream(), bucket, objectNames);

            //生成一个OfDocument的对象
            OfDocument ofDocument = new OfDocument();
            ofDocument.setTitle(titleName1);
            ofDocument.setMainDocName(titleName2);
            ofDocument.setUploadUserNameId(getCurrentUserNameId());
            ofDocument.setUploadUserName(getCurrentUserName());
            ofDocument.setUploadOrgId(getCurrentOrgId());
            ofDocument.setPid(Integer.valueOf(puuid));
            ofDocument.setPeriodValidity(periodValidity);
            ofDocument.setId(ofDocumentMax.get(0).getId() + 1 + i);
            ofDocument.setWhetherFolder("1");
            ofDocument.setIsElectronicDoc("0");
            ofDocument.setDocVersion("1.0");
            ofDocument.setType("标准文档");
            ofDocument.setWhetherDelete("0");
//            ofDocument.setNumberCopies(1);
            if (ofDocument.getNumberCopies() == null || ofDocument.getNumberCopies() <= 0) {
                ofDocument.setNumberCopies(1);
            }

            //判断是否需要上传审核
            if (!"1".equals(pOfDocument.getOfOption())) {
                ofDocument.setState("state.2");
                ofDocument.setApprovalSource("添加文档");
            } else {
                ofDocument.setState("state.1");
            }

            ofDocument.setDocSize(FileUtils.getSizeNum(files.get(i).getSize()));
            ofDocument.setMainDocUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
            ofDocument.setVersionUuid(cn.ewsd.common.utils.BaseUtils.UUIDGenerator());
            ofDocumentService.insertSelective(getSaveData(ofDocument));

            //原先的附件表存一份
            DfsFile dfsFile = new DfsFile();
            dfsFile.setFileName(fileName);
            dfsFile.setCreatorId(getCurrentUserNameId());
            dfsFile.setCreator(getCurrentUserName());
            dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
//            dfsFile.setPuuid(puuid);
            dfsFile.setPuuid(ofDocument.getUuid());
            dfsFile.setFileSize(FileUtils.getSize(files.get(i).getSize()));
            dfsFile.setTenantUuid(LoginInfoVo.getTenantUuid());
            dfsFileService.insertSelective(getSaveData(dfsFile));
            dfsFileUuid = dfsFile.getUuid();
            url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
            object.add(objectWriteResponse.object());
            objectNames = null;

            //生成一个版本的子集
            OfDocumentVersioning ofDocumentVersioning = new OfDocumentVersioning();
            ofDocumentVersioning.setUuid(ofDocument.getVersionUuid());
            ofDocumentVersioning.setVersion("1.0");
            ofDocumentVersioning.setDocId(ofDocument.getId().toString());
            ofDocumentVersioning.setMainDocName(titleName2);
            ofDocumentVersioning.setMainDocSize(FileUtils.getSize(files.get(i).getSize()));
            ofDocumentVersioning.setMainDocUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
            ofDocumentVersioningService.insertSelective(getSaveData(ofDocumentVersioning));
        }
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
        var3.put("", url.get(0));
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
            var3.put("url", url.get(0));
        } else {
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }


//    @ApiOperation("测试接口")
//    @RequestMapping(value = "/uploadWpsFile1", method = RequestMethod.POST)
//    @ResponseBody
//    public Object uploadWpsFile1() throws Exception {
//        HtmlToWord htmlToWord = new HtmlToWord();
//        htmlToWord.htmlToWord2();
//        return 1;
//    }

    /**
     * WPS在线预览上传文件 只允许有一个文件
     *
     * @param bucket     存储桶名称  misboot-cloud-vue
     * @param objectName 保存在存储桶的文件 images/
     * @param oldUrl     原文件地址
     * @return Object
     */
    @ApiOperation("上传文件")
    @RequestMapping(value = "/uploadWpsFile", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadWpsFile(@RequestParam String bucket,
                                @RequestParam(required = false) String objectName,
                                @RequestParam(required = false) String oldUrl, HttpServletRequest request
    ) throws Exception {
        //获取传过来的文件
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
        if (CollUtil.isEmpty(files)) {
            return failure("上传文件不能为空！！！");
        }
        if (ObjectUtil.isEmpty(files.get(0)) || files.get(0).getSize() <= 0) {
            return failure("上传文件不能为空！！！");
        }
        if (files.size() > 1) {
            return failure("正文只允许上传一个");
        }
        if (!StringUtils.isNullOrEmpty(oldUrl)) {
            this.deleteFile(bucket, oldUrl.substring(oldUrl.lastIndexOf("/"), oldUrl.length()));
        }
        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        for (int i = 0; i < files.size(); i++) {
            //上传文件同名，文件名特殊处理
            String fileName = files.get(i).getOriginalFilename();

            //查询敏感字判断
            String sensitives = MacroDefinitionData.SENSITIVE;
            List<String> sensitiveList = Arrays.asList(sensitives.split(","));
            for (String sensitive : sensitiveList) {
                if (fileName.contains(sensitive)) {
                    throw new Exception("上传文件失败，文件名称包含有敏感词！");
                }
            }

            List<DfsFile> list = dfsFileService.getMaxVersionByFileName(files.get(i).getOriginalFilename());
            if (CollUtil.isNotEmpty(list)) {
                fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + files.get(i).getOriginalFilename();
            }
            if (StringUtils.isNullOrEmpty(objectName)) {
                objectNames = fileName;
            } else {
                objectNames = objectName + "/" + fileName;
            }

            ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(files.get(i).getInputStream(), bucket, objectNames);
            DfsFile dfsFile = new DfsFile();
            dfsFile.setFileName(fileName);
            dfsFile.setCreatorId(getCurrentUserNameId());
            dfsFile.setCreator(getCurrentUserName());
            dfsFile.setUrl(minioUrl + "/" + bucket + "/" + objectWriteResponse.object());
            dfsFile.setPuuid("wps");
            dfsFile.setFileSize(FileUtils.getSize(files.get(i).getSize()));
            dfsFile.setTenantUuid(LoginInfoVo.getTenantUuid());
            dfsFileService.insertSelective(getSaveData(dfsFile));
            dfsFileUuid = dfsFile.getUuid();
            url.add(minioUrl + "/" + bucket + "/" + objectWriteResponse.object());
            object.add(objectWriteResponse.object());
            objectNames = null;
        }
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
            var3.put("url", url.get(0));
        } else {
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }

    /**
     * WPS保存新文件
     *
     * @param file       需要上传的新文件
     * @param objectName 保存在存储桶的文件 images/
     * @param fileUrl    原文件路径
     * @return Object
     */
    @ApiOperation("上传文件")
    @RequestMapping(value = "/uploadWps", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadWps(@RequestPart("file") MultipartFile file,
                            String objectName,
                            String fileUrl
    ) throws Exception {
        //获取传过来的文件
        if (null == file || file.isEmpty()) {
            return failure("上传文件不能为空！！！");
        }
        String bucket = "";
        if (!StringUtils.isNullOrEmpty(fileUrl)) {
            bucket = fileUrl.replace(minioUrl, "").substring(0, fileUrl.replace(minioUrl, "").indexOf("/"));
        } else {
            bucket = "vue-wps";
        }
        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        //删除原文件
        this.deleteFile(bucket, fileUrl.substring(fileUrl.lastIndexOf("/") + 1, fileUrl.length()));

        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        //上传文件同名，文件名特殊处理
        String fileName = file.getOriginalFilename();
        //查询敏感字判断
        String sensitives = MacroDefinitionData.SENSITIVE;
        List<String> sensitiveList = Arrays.asList(sensitives.split(","));
        for (String sensitive : sensitiveList) {
            if (fileName.contains(sensitive)) {
                throw new Exception("上传文件失败，文件名称包含有敏感词！");
            }
        }
        List<DfsFile> list = dfsFileService.getMaxVersionByFileName(file.getOriginalFilename());
        if (CollUtil.isNotEmpty(list)) {
            fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + file.getOriginalFilename();
        }
        if (StringUtils.isNullOrEmpty(objectName)) {
            objectNames = fileName;
        } else {
            objectNames = objectName + "/" + fileName;
        }
        ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(file.getInputStream(), bucket, objectNames);
        DfsFile dfsFile = new DfsFile();
        dfsFile.setFileName(fileName);
        dfsFile.setCreatorId(LoginInfo.getUserNameId());
        dfsFile.setCreator(LoginInfo.getUserName());
        dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
        dfsFile.setPuuid("wps");
        dfsFile.setFileSize(FileUtils.getSize(file.getSize()));
        dfsFile.setTenantUuid(LoginInfoVo.getTenantUuid());
        dfsFileService.insertSelective(getSaveData(dfsFile));
        dfsFileUuid = dfsFile.getUuid();
        url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
        object.add(objectWriteResponse.object());
        objectNames = null;
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
            var3.put("url", url.get(0));
        } else {
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }

    @ApiOperation("列出所有的桶")
    @RequestMapping(value = "/listBuckets", method = RequestMethod.POST)
    @ResponseBody
    public Object listBuckets() throws Exception {
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "列出所有的桶");
        var3.put("message", "列出所有的桶成功");
        var3.put("data", minioUtil.listBuckets());
        return var3;
    }


    /**
     * 递归列出一个桶中的所有文件和目录
     *
     * @param bucket 存储桶名称
     * @return 文件保存位置
     * prefix 前缀
     */
    @ApiOperation("递归列出一个桶中的所有文件和目录")
    @RequestMapping(value = "/listFiles", method = RequestMethod.POST)
    @ResponseBody
    public Object listFiles(@RequestParam String bucket, @RequestParam(required = false) String prefix) throws Exception {
        HashMap var3 = new HashMap();
        List<MinioVo> list = minioUtil.listFiles(bucket, prefix);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setSizeText(getSize(list.get(i).getSize()));
        }
        var3.put("statusCode", 200);
        var3.put("title", "递归列出一个桶中的所有文件和目录");
        var3.put("message", "递归列出一个桶中的所有文件和目录");
        var3.put("data", list);
        return var3;
    }

    //将文件大小size转成K、M、G
    public static String getSize(long size) {
        if (size >= 1024 * 1024 * 1024) {
            return new Long(size / 1073741824L) + "G";
        } else if (size >= 1024 * 1024) {
            return new Long(size / 1048576L) + "M";
        } else if (size >= 1024) {
            return new Long(size / 1024) + "K";
        } else {
            return size + "B";
        }
    }

    /**
     * 下载一个文件
     *
     * @param bucket     存储桶名称
     * @param objectName 保存在存储桶的文件 images/a.doc
     * @return 文件保存位置
     */
    @ApiOperation("下载一个文件")
    @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
    public void downloadFile(String bucket, String objectName,
                             HttpServletResponse response) throws Exception {
        InputStream stream = minioUtil.download(bucket, objectName);
        ServletOutputStream output = response.getOutputStream();
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(objectName.substring(objectName.lastIndexOf("/") + 1), "UTF-8"));
        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("UTF-8");
        IOUtils.copy(stream, output);
    }


    /**
     * 下载一个文件
     *
     * @param bucket     存储桶名称
     * @param objectName 保存在存储桶的文件 images/a.doc
     * @return 文件保存位置
     */
    @ApiOperation("获取InputStream")
    @RequestMapping(value = "/getInputStream", method = RequestMethod.GET)
    public InputStream getInputStream(String bucket, String objectName) throws Exception {
        InputStream stream = minioUtil.download(bucket, objectName);
        return stream;
    }

    /**
     * 下载一个文件
     *
     * @param bucket     存储桶名称
     * @param objectName 保存在存储桶的文件 images/a.doc
     * @return 文件保存位置
     */
    @ResponseBody
    @ApiOperation("获取InputStream")
    @RequestMapping(value = "/getInpuatStream")
    public void getInputStraeam(HttpServletResponse httpServletResponse, String bucket, String objectName) throws Exception {
        InputStream stream = minioUtil.download(bucket, objectName);
        OutputStream out = null;
        byte[] buf = new byte[1024];
        int legth = 0;
        try {
            out = httpServletResponse.getOutputStream();
            while ((legth = stream.read(buf)) != -1) {
                out.write(buf, 0, legth);
            }
        } finally {
//            if (stream != null) {
//                stream.close();
//            }
//            if (out != null) {
//                out.close();
//            }
        }

    }

    /**
     * 下载一个文件
     *
     * @param bucket     存储桶名称
     * @param objectName 保存在存储桶的文件 images/a.doc
     * @return 文件保存位置
     */
    @ApiOperation("获取InputStream")
    @ResponseBody
    @RequestMapping(value = "/getInputStreamByUrl", method = RequestMethod.GET)
    public void getInputStreamByUrl(HttpServletResponse httpServletResponse, String url) throws Exception {
        url = url.replace(minioUrl, "");
        String bucket = url.substring(0, url.indexOf("/"));
        String objectName = url.substring(url.indexOf("/") + 1);
        InputStream stream = minioUtil.download(bucket, objectName);
        OutputStream out = null;
        byte[] buf = new byte[1024];
        int legth = 0;
        try {
            out = httpServletResponse.getOutputStream();
            while ((legth = stream.read(buf)) != -1) {
                out.write(buf, 0, legth);
            }
        } finally {
            if (stream != null) {
                stream.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }

    @RequestMapping(value = "/getInputStreamByUuid", method = RequestMethod.POST)
    @ResponseBody
    public void getInputStreamByUuid(@RequestParam("dfsFileUuid") String dfsFileUuid, HttpServletResponse httpServletResponse) {
        DfsFile dfsFile = dfsFileService.selectByPrimaryKey(dfsFileUuid);
        String url = dfsFile.getUrl();
        url = url.replace(minioUrl, "");
        String bucket = url.substring(0, url.indexOf("/"));
        String objectName = url.substring(url.indexOf("/") + 1);
        InputStream stream = null;
        try {
            stream = minioUtil.download(bucket, objectName);
            OutputStream out = null;
            byte[] buf = new byte[1024];
            int legth = 0;
            try {
                out = httpServletResponse.getOutputStream();
                while ((legth = stream.read(buf)) != -1) {
                    out.write(buf, 0, legth);
                }
            } finally {
                if (stream != null) {
                    stream.close();
                }
                if (out != null) {
                    out.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 多文件下载打包
     *
     * @param bucket     存储桶名称
     * @param objectName 保存在存储桶的文件 images/a.doc
     * @return 文件保存位置
     */
    @ApiOperation("多文件下载打包")
    @RequestMapping(value = "/downloadFileZip", method = RequestMethod.GET)
    public void downloadFileZip(String bucket, String objectName, String title,
                                HttpServletResponse response) throws Exception {
        String str[] = objectName.split(",");
        //被压缩文件InputStream
        InputStream[] srcFiles = new InputStream[str.length];
        //被压缩文件名称
        String[] srcFileNames = new String[str.length];
        for (int i = 0; i < str.length; i++) {
            InputStream inputStream = minioUtil.download(bucket, str[i]);
            if (inputStream == null) {
                continue;
            }
            srcFiles[i] = inputStream;
            String[] splitFileUrl = str[i].split("/");
            srcFileNames[i] = splitFileUrl[splitFileUrl.length - 1];
        }
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(title + ".zip", "UTF-8"));
        //多个文件压缩成压缩包返回
        ZipUtil.zip(response.getOutputStream(), srcFileNames, srcFiles);
    }

    /**
     * @MethodName 生成临时1天有效链接
     * @Description
     * @Param fileuUrl 文件地址
     * @Return java.lang.Object
     * @Author 朱永敬<zhuyongjing @ zuoyour.com>
     * @Date 2020-10-13 19:20
     */
    @ApiOperation(value = "生成临时1天有效链接")
    @RequestMapping("/getGenerateTemporaryUrl")
    @ResponseBody
    public Object getGenerateTemporaryUrl(String fileuUrl) throws Exception {
        boolean is = fileuUrl.contains("?X-Amz-Algorithm");
        if (!is) {
            String bucket = "";
            String objectName = "";
            //截取桶名及文件名
            Integer urlLength = minioUrl.length();
            String fileuUrlName = fileuUrl.substring(urlLength, fileuUrl.length());
            bucket = fileuUrlName.substring(0, fileuUrlName.indexOf("/"));//截取/之前的字符串
            objectName = fileuUrlName.substring(fileuUrlName.indexOf("/") + 1, fileuUrlName.length());//截取/后的字符串
            objectName = URLDecoder.decode(objectName, "UTF-8");
            int days = 1;
            String url = minioClient.getPresignedObjectUrl(
                    GetPresignedObjectUrlArgs.builder()
                            .method(Method.GET)
                            .bucket(bucket)
                            .object(objectName)
                            .expiry(days, TimeUnit.DAYS)
                            .build());
            return url.replace(" ", "");
        } else {
            return fileuUrl.replace(" ", "");
        }
    }


    @ApiOperation("删除一个文件")
    @RequestMapping(value = "/deleteFile", method = RequestMethod.POST)
    @ResponseBody
    public Object deleteFile(@RequestParam String bucket, String objectName) throws Exception {
        String[] objectNameArr = objectName.split(",");
        for (int i = 0; i < objectNameArr.length; i++) {
            minioUtil.deleteObject(bucket, objectNameArr[i]);
//            //本地数据库的数据也删除掉
            dfsFileService.executeDeleteByName(objectNameArr[i]);
        }
        return success("删除文件成功 ！");
    }

    @ApiOperation("删除一个文件")
    @RequestMapping(value = "/deleteFileWps", method = RequestMethod.POST)
    @ResponseBody
    public Object deleteFileWps(@RequestParam String bucket, String objectName) throws Exception {
        String[] objectNameArr = objectName.split(",");
        for (int i = 0; i < objectNameArr.length; i++) {
            minioUtil.deleteObject(bucket, objectNameArr[i]);
        }
        return success("删除文件成功 ！");
    }

    @ApiOperation("更新一个文件")
    @RequestMapping(value = "/updateFile", method = RequestMethod.POST)
    @ResponseBody
    public Object updateFile(MultipartFile file, String bucket, String objectName) throws Exception {

        String[] objectNameArr = objectName.split(",");
        for (int i = 0; i < objectNameArr.length; i++) {
            minioUtil.deleteObject(bucket, objectNameArr[i]);
        }

        //获取传过来的文件
        if (null == file || file.isEmpty()) {
            return failure("上传文件不能为空！！！");
        }

        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }

        ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(file.getInputStream(), bucket, objectName);
        if (objectWriteResponse != null) {
            return success("更新成功");
        }
        return failure("更新失败");

    }

    @ApiOperation("获取桶名和带目录的完整文件名")
    @RequestMapping(value = "/getBucket", method = RequestMethod.POST)
    @ResponseBody
    public Object getBucketAndFileName(@RequestParam String url) {
        String bucket = url.substring(minioUrl.length(), url.indexOf("/", minioUrl.length()));
        String fileName = url.substring(url.indexOf("/", minioUrl.length()) + 1);
        HashMap<String, String> map = new HashMap<>();
        map.put("bucket", bucket);
        map.put("fileName", fileName);
        return map;
    }

    @ApiOperation("删除一个文件")
    @RequestMapping(value = "/deleteFileByUrl", method = RequestMethod.POST)
    @ResponseBody
    public Object deleteFileByUrl(@RequestParam String url) throws Exception {
        if (StringUtils.isNullOrEmpty(url)) {
            return failure("参数url为空");
        }
        url = url.replace(minioUrl, "");
        String bucket = url.substring(0, url.indexOf("/"));
        String objectName = url.substring(url.indexOf("/") + 1);
        minioUtil.deleteObject(bucket, objectName);
        //本地数据库的数据也删除掉
        dfsFileService.executeDeleteByName(objectName);
        return success("删除文件成功 ！");
    }

    @ApiOperation("删除一个桶")
    @RequestMapping(value = "/deleteBucket", method = RequestMethod.POST)
    @ResponseBody
    public Object deleteBucket(@RequestParam String bucket) throws Exception {
        if (StrUtil.isBlank(bucket)) {
            return failure("必要参数bucket不能为空！！！");
        }
        String str[] = bucket.split(",");
        for (int i = 0; i < str.length; i++) {
            minioUtil.deleteBucket(str[i]);
        }
        return success("删除桶成功 ！");
    }


    /**
     * 生成http访问地址
     *
     * @param bucket     存储桶名称
     * @param objectName 保存在存储桶的文件 images/a.doc
     *                   expiry 失效时间（以秒为单位），默认是7天，不得大于七天。
     *                   method 请求方式
     * @return 文件保存位置
     */
    @ApiOperation("生成http访问地址(GET)")
    @RequestMapping(value = "/getPresignedObjectUrl", method = RequestMethod.POST)
    @ResponseBody
    public Object getPresignedObjectUrl(@RequestParam(required = false) String bucket,
                                        @RequestParam(required = false) String objectName, @RequestParam(required = false) int days) throws Exception {
        if (days == 0) {
            days = 1;
        }
        String url = minioClient.getPresignedObjectUrl(
                GetPresignedObjectUrlArgs.builder()
                        .method(Method.GET)
                        .bucket(bucket)
                        .object(objectName)
//                                .expiry(24 * 60 * 60)
                        .expiry(days, TimeUnit.DAYS)
                        .build());
        url = URLDecoder.decode(url, "UTF-8");
        return url;
    }

    /**
     * 生成http访问地址
     *
     * @param bucket     存储桶名称
     * @param objectName 保存在存储桶的文件 images/a.doc
     *                   expiry 失效时间（以秒为单位），默认是7天，不得大于七天。
     *                   method 请求方式
     * @return 文件保存位置
     */
    @ApiOperation("生成http访问地址(GET)")
    @RequestMapping(value = "/getShareUrlByUrl", method = RequestMethod.POST)
    @ResponseBody
    public String getShareUrlByUrl(@RequestParam(required = false) String url) throws Exception {
        int days = 1;
        url = url.replace(minioUrl, "");
        String bucket = url.substring(0, url.indexOf("/"));
        String objectName = url.substring(url.indexOf("/") + 1);
        String shareUrl = minioClient.getPresignedObjectUrl(
                GetPresignedObjectUrlArgs.builder()
                        .method(Method.GET)
                        .bucket(bucket)
                        .object(objectName)
//                                .expiry(24 * 60 * 60)
                        .expiry(days, TimeUnit.DAYS)
                        .build());
//        url = URLDecoder.decode(url, "UTF-8");
        return shareUrl;
    }


    /**
     * fileuUrl http://192.168.1.216:9000/zysd-test02/20210901112210-202103221551190311_72538.png
     * 图片预览
     */
    @ApiOperation("图片预览")
    @RequestMapping(value = "/showPic")
    @ResponseBody
    public Object showPic(String fileuUrl) throws Exception {
        String bucket = "";
        String objectName = "";
        //截取桶名及文件名
        Integer urlLength = minioUrl.length();
        if (fileuUrl.indexOf(minioUrl) == -1) {
            fileuUrl = minioUrl + fileuUrl;
        }
        String fileuUrlName = fileuUrl.substring(urlLength, fileuUrl.length());
        bucket = fileuUrlName.substring(0, fileuUrlName.indexOf("/"));//截取/之前的字符串
        objectName = fileuUrlName.substring(fileuUrlName.indexOf("/") + 1, fileuUrlName.length());//截取/后的字符串
        InputStream stream = minioUtil.download(bucket, objectName);
        byte[] data = readInputStream(stream);
        HttpHeaders headers = new HttpHeaders();
        String fileName = new String(objectName.getBytes("UTF-8"), "iso-8859-1");//为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(data, headers, HttpStatus.CREATED);
    }

    /**
     * @MethodName pdfStreamHandeler
     * @Description 返回pdf流文件
     * @Param request
     * @Param response
     * @Return void
     * @Author 宋景民<songjingmin @ zuoyoutech.com>
     * @Date 2019/1/21 11:31
     */
    @ApiOperation("返回pdf流文件")
    @RequestMapping(value = "/pdfStreamHandeler", method = {RequestMethod.POST, RequestMethod.GET})
    public void pdfStreamHandeler(String fileuUrl, HttpServletRequest request, HttpServletResponse response) {
        String bucket = "";
        String objectName = "";
        //截取桶名及文件名
        Integer urlLength = minioUrl.length();
        if (fileuUrl.indexOf(minioUrl) == -1) {
            fileuUrl = minioUrl + fileuUrl;
        }
        String fileuUrlName = fileuUrl.substring(urlLength, fileuUrl.length());
        bucket = fileuUrlName.substring(0, fileuUrlName.indexOf("/"));//截取/之前的字符串
        objectName = fileuUrlName.substring(fileuUrlName.indexOf("/") + 1, fileuUrlName.length());//截取/后的字符串
        byte[] data = null;
        try {
            response.setContentType("application/pdf");
            InputStream input = minioUtil.download(bucket, objectName);
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            //创建一个Buffer字符串
            byte[] buffer = new byte[1024];
            //每次读取的字符串长度，如果为-1，代表全部读取完毕
            int len = 0;
            //使用一个输入流从buffer里把数据读取出来
            while ((len = input.read(buffer)) != -1) {
                //用输出流往buffer里写入数据，中间参数代表从哪个位置开始读，len代表读取的长度
                outStream.write(buffer, 0, len);
            }
            //把outStream里的数据写入内存
            data = outStream.toByteArray();
            input.read(data);
            response.getOutputStream().write(data);
            input.close();
        } catch (Exception e) {
            System.out.println(e);
        }

    }


    /**
     * @MethodName pdfStreamHandeler
     * @Description 返回pdf流文件
     * @Param request
     * @Param response
     * @Return void
     * @Author 宋景民<songjingmin @ zuoyoutech.com>
     * @Date 2019/1/21 11:31
     */
    @ApiOperation("返回视频流文件")
    @RequestMapping(value = "/pdfStreamVideo", method = {RequestMethod.POST, RequestMethod.GET})
    public void pdfStreamVideo(String fileuUrl, HttpServletRequest request, HttpServletResponse response) {
        String bucket = "";
        String objectName = "";
        //截取桶名及文件名
        Integer urlLength = minioUrl.length();
        if (fileuUrl.indexOf(minioUrl) == -1) {
            fileuUrl = minioUrl + fileuUrl;
        }
        String fileuUrlName = fileuUrl.substring(urlLength, fileuUrl.length());
        bucket = fileuUrlName.substring(0, fileuUrlName.indexOf("/"));//截取/之前的字符串
        objectName = fileuUrlName.substring(fileuUrlName.indexOf("/") + 1, fileuUrlName.length());//截取/后的字符串
        byte[] data = null;
        try {
            //// 解决请求头跨域问题（IE兼容性  也可使用该方法）
//            response.setHeader("Access-Control-Allow-Credentials", "true");
//            response.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH");
//            response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type,Token,Accept, Connection, User-Agent, Cookie");
//            response.setHeader("Access-Control-Max-Age", "3628800");
//            response.setHeader("Access-Control-Allow-Origin", "*");
//            response.setContentType("application/pdf");
            response.setContentType("application/video");
            InputStream input = minioUtil.download(bucket, objectName);
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            //创建一个Buffer字符串
            byte[] buffer = new byte[1024];
            //每次读取的字符串长度，如果为-1，代表全部读取完毕
            int len = 0;
            //使用一个输入流从buffer里把数据读取出来
            while ((len = input.read(buffer)) != -1) {
                //用输出流往buffer里写入数据，中间参数代表从哪个位置开始读，len代表读取的长度
                outStream.write(buffer, 0, len);
            }
            //把outStream里的数据写入内存
            data = outStream.toByteArray();
            input.read(data);
            response.getOutputStream().write(data);
            input.close();
        } catch (Exception e) {
            System.out.println(e);
        }

    }

    public static byte[] readInputStream(InputStream inStream) throws Exception {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        //创建一个Buffer字符串
        byte[] buffer = new byte[1024];
        //每次读取的字符串长度，如果为-1，代表全部读取完毕
        int len = 0;
        //使用一个输入流从buffer里把数据读取出来
        while ((len = inStream.read(buffer)) != -1) {
            //用输出流往buffer里写入数据，中间参数代表从哪个位置开始读，len代表读取的长度
            outStream.write(buffer, 0, len);

        }
        //关闭输入流
        inStream.close();
        //把outStream里的数据写入内存
        return outStream.toByteArray();

    }


    @ApiOperation("创建一个桶")
    @RequestMapping(value = "/createBucket", method = RequestMethod.POST)
    @ResponseBody
    public Object createBucket(@RequestParam(required = true) String bucket) throws Exception {
        if (StrUtil.isBlank(bucket)) {
            return failure("必要参数bucket不能为空！！！");
        }
        if (!RegexUtil.BucketRegex(bucket)) {
            return failure("存储桶名称只能是小写字母,数字,横线。必须以小写字母或数字开头,不能以横线结尾, 长度3到63个字符之间！！！");
        }
        boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
        if (found) {
            return failure("存储桶名称已存在,请修改为其他名称！！！");
        }
        minioUtil.createBucket(bucket);
        return success("创建一个桶成功 ！");
    }


    @ApiOperation("大屏报表图片上传")
    @RequestMapping(value = {"/reportVisualPutFile.api", "reportVisualPutFile"})
    @ResponseBody
    public Object reportVisualPutFile(@RequestParam("file") MultipartFile file) throws Exception {
        String bucket = "datav";
        String objectName = "";
        //创建桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        //上传文件同名，文件名特殊处理
        String fileName = "";
        List<DfsFile> list = dfsFileService.getMaxVersionByFileName(file.getOriginalFilename());
        if (null != list && !list.isEmpty()) {
            String format = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
            fileName = format + "-" + file.getOriginalFilename();
        } else {
            fileName = file.getOriginalFilename();
        }
        if (StringUtils.isNullOrEmpty(objectName)) {
            objectName = fileName;
        } else {
            objectName = objectName + "/" + fileName;
        }
        ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(file.getInputStream(), bucket, objectName);
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("bucket", objectWriteResponse.bucket());
        var3.put("object", objectWriteResponse.object());
        var3.put("url", minioUrl + bucket + "/" + objectWriteResponse.object());
        var3.put("message", "上传文件成功");
        return var3;
    }

    /**
     * DCM后端上传文件(用于替换文件)
     *
     * @param bucket     存储桶名称
     * @param objectName 原文件地址
     * @return 文件保存位置
     */
    @ApiOperation("上传一个文件")
    @RequestMapping(value = "/uploadfilesdcmNoYYMMdd")
    @ResponseBody
    public Object uploadfilesdcmNoYYMMdd(MultipartFile multipartFile, @RequestParam String bucket,
                                         @RequestParam(required = false) String objectName, String uuid) {
        HashMap var3 = new HashMap();
        try {
            // 获得文件类型，放入相应的文件夹
            String fileType = "";
            //重新赋值固定
//            bucket =fileType;
            //创建桶
            if (!minioUtil.bucketExists(bucket)) {
                minioUtil.createBucket(bucket);
            }

            if (BeanUtil.isNotEmpty(objectName)) {
                objectName = checkForSpecialCharsAndGetNewFileName(objectName);
            }
            ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(multipartFile.getInputStream(), bucket, objectName);

            if (StrUtil.isNotBlank(uuid)) {
                DfsFile dfsFile = new DfsFile();
                dfsFile.setFileName(objectName);
                dfsFile.setCreatorId(LoginInfo.getUserNameId());
                dfsFile.setCreator(LoginInfo.getUserName());
                dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
                dfsFile.setPuuid(uuid);
                dfsFile.setFileSize(FileUtils.getSize(multipartFile.getSize()));
                dfsFile.setUuid(cn.ewsd.common.utils.BaseUtils.UUIDGenerator());
                dfsFile.setCreateTime(new Date());
                dfsFileService.insertSelective(dfsFile);
            }

            var3.put("statusCode", 200);
            var3.put("title", "上传文件成功");
            var3.put("message", "上传文件成功");
            var3.put("bucket", objectWriteResponse.bucket());
            var3.put("object", objectWriteResponse.object());
            var3.put("url", minioUrl + bucket + "/" + objectWriteResponse.object());
            var3.put("filePath", minioUrl + bucket + "/" + objectWriteResponse.object());
        } catch (Exception e) {
            e.printStackTrace();
            var3.put("statusCode", 300);
            var3.put("title", "文件上传失败");
            var3.put("message", "文件上传失败");
            var3.put("bucket", "");
            var3.put("object", "");
            var3.put("url", "");
            var3.put("filePath", "");
        }
        return var3;
    }

    private String checkForSpecialCharsAndGetNewFileName(String originalFileName) {
        final String[] splChars = {"#", "+", "$", " ", "[\\s\\u00A0]", "?", "*", "!", "@", "%", "^", "&", "（", "）", "=", "[", "]"};
        for (int i = 0; i < splChars.length; i++) {
            if ("（".equals(splChars[i])) {
                originalFileName = originalFileName.replace("（", "(");
            } else if ("）".equals(splChars[i])) {
                originalFileName = originalFileName.replace("）", ")");
            } else if ("[".equals(splChars[i])) {
                originalFileName = originalFileName.replace("[", "(");
            } else if ("]".equals(splChars[i])) {
                originalFileName = originalFileName.replace("]", ")");
            } else {
                if (splChars[i].equals("[\\s\\u00A0]")) {
                    originalFileName = originalFileName.replaceAll(splChars[i], "_");
                } else {
                    originalFileName = originalFileName.replace(splChars[i], "_");
                }
            }
        }
        return originalFileName;
    }

    /**
     * .
     *
     * @param file        入参 文件
     * @param imageWidth  入参 图片宽度
     * @param imageHeight 入参  图片高度
     * @return boolean 是否满足
     * @Description: 作用:   上传图片宽度和高度都小于等于规定最大值
     * @Author: ZYJ
     * @Date: 2022/3/3 16:44
     */
    public static boolean checkImageElement(File file, int imageWidth, int imageHeight) throws IOException {
        Boolean result = false;
        if (!file.exists()) {
            return false;
        }
        BufferedImage bufferedImage = ImageIO.read(file);
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        logger.info("图片宽高---" + width + "---" + height);
        logger.info("规定宽高---" + imageWidth + "---" + imageHeight);
        if (bufferedImage != null && height == imageHeight && width == imageWidth) {
            result = true;
        }
        return result;
    }

    /**
     * .
     *
     * @param file        入参 图片
     * @param imageWidth  入参 图片宽度
     * @param imageHeight 入参 图片高度
     * @return boolean 是否满足
     * @Description: 作用:  校验图片比例
     * @Author: ZYJ
     * @Date: 2022/3/3 16:49
     */
    public static boolean checkImageScale(File file, int imageWidth, int imageHeight) throws IOException {
        Boolean result = false;
        if (!file.exists()) {
            return false;
        }
        BufferedImage bufferedImage = ImageIO.read(file);
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        if (imageHeight != 0 && height != 0) {
            int scale1 = imageHeight / imageWidth;
            int scale2 = height / width;
            logger.info("规定图片比例" + scale1);
            logger.info("实际图片比例" + scale2);
            if (scale1 == scale2) {
                result = true;
            }
        }
        return result;
    }

    @ResponseBody
    @ApiOperation("将一个文件从一个桶复制到另外一个桶中")
    @RequestMapping(value = "/copyFileToBucket")
    public Result copyFileToBucket(String bucket, String bucketCopy, String fileName1, String fileName2) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, NoSuchAlgorithmException, InvalidKeyException {
        // 使用CopyObjectArgs.Builder复制对象
        ObjectWriteResponse objectWriteResponse = minioClient.copyObject(
                CopyObjectArgs.builder()
                        .bucket(bucketCopy) // 目标桶
                        .object(fileName2) // 目标对象名
                        .source(
                                CopySource.builder()
                                        .bucket(bucket) // 源桶
                                        .object(fileName1) // 源对象名
                                        .build())
                        .build());
        if (ObjectUtil.isEmpty(objectWriteResponse)) {
            return Result.ofFailMsg("复制失败");
        }
        return Result.ofSuccessMsg("复制成功");
    }

    @ResponseBody
    @ApiOperation("修改文件名字")
    @RequestMapping(value = "/updateFileName")
    public Result updateFileName(String bucket, String oldFileName, String newFileName) {
//        oldFileName = "file/" + oldFileName;
//        newFileName = "file/" + newFileName;
        try {
            // 使用copyObject方法将源对象复制到目标对象
            minioClient.copyObject(
                    CopyObjectArgs.builder()
                            .bucket(bucket)
                            .object(newFileName)
                            .source(
                                    CopySource.builder()
                                            .bucket(bucket)
                                            .object(oldFileName)
                                            .build())
                            .build());

            // 删除源对象
            minioUtil.deleteObject(bucket, oldFileName);
        } catch (Exception e) {
            System.out.println("Error occurred: " + e);
        }
        return Result.ofSuccessMsg("文件重命名成功");
    }

    /**
     * 上传文件
     *
     * @param objectName 保存在存储桶的文件 images/
     * @return Object
     */
    @ApiOperation("上传文件")
    @RequestMapping(value = "/uploadMultipartFileNew", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadMultipartFileNew(
                                         @RequestPart("file") MultipartFile file,
                                         @RequestParam("bucket") String bucket,
                                         @RequestParam("objectName") String objectName
    ) throws Exception {
        //获取传过来的文件
        if (null == file || file.isEmpty()) {
            return failure("上传文件不能为空！！！");
        }
        //查询敏感字判断
        String sensitives = MacroDefinitionData.SENSITIVE;
        List<String> sensitiveList = Arrays.asList(sensitives.split(","));
//        for (String sensitive: sensitiveList){
//            if(objectName.contains(sensitive)){
//                throw new Exception("上传文件失败，文件名称包含有敏感词！");
//            }
//        }

        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        //上传文件同名，文件名特殊处理
        String fileName = file.getOriginalFilename();
        for (String sensitive : sensitiveList) {
            if (fileName.contains(sensitive)) {
                throw new Exception("上传文件失败，上传文件包含有敏感词！");
            }
        }
        List<DfsFile> list = dfsFileService.getMaxVersionByFileName(file.getOriginalFilename());
        if (CollUtil.isNotEmpty(list)) {
            fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + file.getOriginalFilename();
        }
        if (StringUtils.isNullOrEmpty(objectName)) {
            objectNames = fileName;
        } else {
            objectNames = objectName + "/" + fileName;
        }
        ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(file.getInputStream(), bucket, objectNames);
        DfsFile dfsFile = new DfsFile();
        dfsFile.setFileName(fileName);
        dfsFile.setCreatorId(getCurrentUserNameId());
        dfsFile.setCreator(getCurrentUserName());
        dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
        dfsFile.setPuuid("");
        dfsFile.setFileSize(FileUtils.getSize(file.getSize()));
//        dfsFile.setTenantUuid(LoginInfoVo.getTenantUuid());
        dfsFileService.insertSelective(getSaveData(dfsFile));
        dfsFileUuid = dfsFile.getUuid();
        url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
        object.add(objectWriteResponse.object());
        objectNames = null;
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
            var3.put("url", url.get(0));
        } else {
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }

    /**
     * 上传文件
     *
     * @return Object
     */
    @ApiOperation("上传文件")
    @RequestMapping(value = "/uploadMultipartFileNoObjectName", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadMultipartFileNoObjectName(
            @RequestPart("file") MultipartFile file,
            @RequestParam("bucket") String bucket
    ) throws Exception {
        //获取传过来的文件
        if (null == file || file.isEmpty()) {
            return failure("上传文件不能为空！！！");
        }
        //查询敏感字判断
        String sensitives = MacroDefinitionData.SENSITIVE;
        List<String> sensitiveList = Arrays.asList(sensitives.split(","));
//        for (String sensitive: sensitiveList){
//            if(objectName.contains(sensitive)){
//                throw new Exception("上传文件失败，文件名称包含有敏感词！");
//            }
//        }

        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        //上传文件同名，文件名特殊处理
        String fileName = file.getOriginalFilename();
        for (String sensitive : sensitiveList) {
            if (fileName.contains(sensitive)) {
                throw new Exception("上传文件失败，上传文件包含有敏感词！");
            }
        }
        List<DfsFile> list = dfsFileService.getMaxVersionByFileName(file.getOriginalFilename());
        if (CollUtil.isNotEmpty(list)) {
            fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + file.getOriginalFilename();
        }
        objectNames = fileName;
        ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(file.getInputStream(), bucket, objectNames);
        DfsFile dfsFile = new DfsFile();
        dfsFile.setFileName(fileName);
        dfsFile.setCreatorId(getCurrentUserNameId());
        dfsFile.setCreator(getCurrentUserName());
        dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
        dfsFile.setPuuid("");
        dfsFile.setFileSize(FileUtils.getSize(file.getSize()));
//        dfsFile.setTenantUuid(LoginInfoVo.getTenantUuid());
        dfsFileService.insertSelective(getSaveData(dfsFile));
        dfsFileUuid = dfsFile.getUuid();
        url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
        object.add(objectWriteResponse.object());
        objectNames = null;
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
//        var3.put("docSize", FileUtils.getSize(files.get(0).getSize()));
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
            var3.put("url", url.get(0));
        } else {
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }

    /**
     * 上传文件
     * @param objectName 保存在存储桶的文件 images/
     * @return Object
     */
    @ApiOperation("上传文件-无需token")
    @RequestMapping(value = "/uploadMultipartFileNew.api", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadMultipartFileNewNoToken(@RequestPart("file") MultipartFile file,@RequestParam("bucket") String bucket,@RequestParam("objectName") String objectName) throws Exception {
        //获取传过来的文件
        if (null == file || file.isEmpty()) {
            return failure("上传文件不能为空！！！");
        }
        //查询敏感字判断
        String sensitives = MacroDefinitionData.SENSITIVE;
        List<String> sensitiveList = Arrays.asList(sensitives.split(","));
//        for (String sensitive: sensitiveList){
//            if(objectName.contains(sensitive)){
//                throw new Exception("上传文件失败，文件名称包含有敏感词！");
//            }
//        }

        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        //上传文件同名，文件名特殊处理
        String fileName = file.getOriginalFilename();
        for (String sensitive : sensitiveList) {
            if (fileName.contains(sensitive)) {
                throw new Exception("上传文件失败，上传文件包含有敏感词！");
            }
        }
        List<DfsFile> list = dfsFileService.getMaxVersionByFileName(file.getOriginalFilename());
        if (CollUtil.isNotEmpty(list)) {
            fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + file.getOriginalFilename();
        }
        if (StringUtils.isNullOrEmpty(objectName)) {
            objectNames = fileName;
        } else {
            objectNames = objectName + "/" + fileName;
        }
        ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(file.getInputStream(), bucket, objectNames);
        DfsFile dfsFile = new DfsFile();
        dfsFile.setFileName(fileName);
        dfsFile.setCreatorId(getCurrentUserNameId());
        dfsFile.setCreator(getCurrentUserName());
        dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
        dfsFile.setPuuid("");
        dfsFile.setFileSize(FileUtils.getSize(file.getSize()));
        dfsFile.setUuid(cn.ewsd.common.utils.BaseUtils.UUIDGenerator());
        dfsFile.setCreateTime(new Date());
        dfsFileService.insertSelective(dfsFile);
        dfsFileUuid = dfsFile.getUuid();
        url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
        object.add(objectWriteResponse.object());
        objectNames = null;
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
            var3.put("url", url.get(0));
        } else {
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }

    @ApiOperation("上传文件")
    @RequestMapping(value = "/uploadfileOnlyTable", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadfileOnlyTable(@RequestParam String bucket,
                             @RequestParam(required = false) String objectName,
                             @RequestParam(required = false) String puuid, HttpServletRequest request
    ) throws Exception {
        //获取传过来的文件
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
        if (CollUtil.isEmpty(files)) {
            return failure("上传文件不能为空！！！");
        }
        //查询敏感字判断
        String sensitives = MacroDefinitionData.SENSITIVE;
        List<String> sensitiveList = Arrays.asList(sensitives.split(","));
//        for (String sensitive: sensitiveList){
//            if(objectName.contains(sensitive)){
//                throw new Exception("上传文件失败，文件名称包含有敏感词！");
//            }
//        }
        for (int i = 0; i < files.size(); i++) {
            if (ObjectUtil.isEmpty(files.get(i)) || files.get(i).getSize() <= 0) {
                return failure("上传文件不能为空！！！");
            }
            String fileName = files.get(i).getOriginalFilename();
            for (String sensitive : sensitiveList) {
                if (fileName.contains(sensitive)) {
                    throw new Exception("上传文件失败，上传文件包含有敏感词！");
                }
            }
        }
        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        String objectNames = null;
        String dfsFileUuid = "";
        for (int i = 0; i < files.size(); i++) {
            //上传文件同名，文件名特殊处理
            String originalFilename = files.get(i).getOriginalFilename();//原始文件名
            String fileName = originalFilename;

            //特殊处理-解决使用URL获取minio文件报错的问题
            fileName = fileName.replaceAll("\\(","").replaceAll("\\)","");
            fileName = fileName.replaceAll("\\（","").replaceAll("\\）","");
            fileName = fileName.replaceAll(" ","");

            List<DfsFile> list = dfsFileService.getMaxVersionByFileName(files.get(i).getOriginalFilename());
            if (CollUtil.isNotEmpty(list)) {
                fileName = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + fileName;
                originalFilename = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + "-" + files.get(i).getOriginalFilename();
            }
            if (StringUtils.isNullOrEmpty(objectName)) {
                objectNames = fileName;
            } else {
                objectNames = objectName + "/" + fileName;
            }
//            ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(files.get(i).getInputStream(), bucket, objectNames);
            DfsFile dfsFile = new DfsFile();
            dfsFile.setRemark(files.get(i).getOriginalFilename());
            dfsFile.setFileName(originalFilename);
            dfsFile.setRemark(files.get(i).getOriginalFilename());
            dfsFile.setCreatorId(getCurrentUserNameId());
            dfsFile.setCreator(getCurrentUserName());
//            dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
            dfsFile.setPuuid(puuid);
            dfsFile.setFileSize(FileUtils.getSize(files.get(i).getSize()));
            dfsFile.setTenantUuid(LoginInfoVo.getTenantUuid());
            dfsFileService.insertSelective(getSaveData(dfsFile));
            dfsFileUuid = dfsFile.getUuid();
//            url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
//            object.add(objectWriteResponse.object());
            objectNames = null;
        }
        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
        var3.put("docSize", FileUtils.getSize(files.get(0).getSize()));
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
//            var3.put("object", files.get(0).getOriginalFilename());
            var3.put("url", url.get(0));
        } else {
//            var3.put("object", files.get(0).getOriginalFilename());
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }

    @ApiOperation("上传文件")
    @RequestMapping(value = "/uploadfileByUuid", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadfileByUuid(@RequestParam("dfsFileUuid") String dfsFileUuid,@RequestParam("bucket") String bucket, @RequestPart("file") MultipartFile file) throws Exception {
        //获取传过来的文件
        //查询敏感字判断
        //创建存储桶
        if (!minioUtil.bucketExists(bucket)) {
            minioUtil.createBucket(bucket);
        }
        List<String> url = new ArrayList<>();
        List<String> object = new ArrayList<>();
        DfsFile dfsFile = dfsFileService.selectByPrimaryKey(dfsFileUuid);
        ObjectWriteResponse objectWriteResponse = minioUtil.uploadFile(file.getInputStream(), bucket, dfsFile.getFileName());
        dfsFile.setUrl(minioUrl + bucket + "/" + objectWriteResponse.object());
        url.add(minioUrl + bucket + "/" + objectWriteResponse.object());
        dfsFileService.updateByPrimaryKeySelective(dfsFile);
        object.add(objectWriteResponse.object());


        HashMap var3 = new HashMap();
        var3.put("statusCode", 200);
        var3.put("title", "上传文件成功");
        var3.put("message", "上传文件成功");
        var3.put("dfsFileUuid", dfsFileUuid);
        var3.put("docSize", dfsFile.getFileSize());
        var3.put("bucket", bucket);
        if (1 == url.size()) {
            var3.put("object", object.get(0));
//            var3.put("object", files.get(0).getOriginalFilename());
            var3.put("url", url.get(0));
        } else {
//            var3.put("object", files.get(0).getOriginalFilename());
            var3.put("object", object);
            var3.put("url", url);
        }
        return var3;
    }

}
